package com.sgb.kjwl.view.ui.adapter.transport.owner;

import android.content.res.Resources;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.makeramen.roundedimageview.RoundedImageView;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.self.GoodsManageItemData;
import com.sgb.kjwl.model.entity.transport.TrucksCarrier;
import com.sgb.kjwl.utils.NumberUtil;
import com.swgk.core.customview.SeeMoreView;
import com.swgk.core.util.DateUtils;

import java.util.List;

/**
 * @Author : 熊丽
 * @date :2021/4/12 0012$ 17:03$
 * @Description ://货车承运适配器$
 */
public class FreightCarTransportationAdapter extends BaseQuickAdapter<TrucksCarrier, BaseViewHolder> {
    private GoodsOperationListener listener;

    private boolean isGeneralGoods;


    public interface GoodsOperationListener {
        void OnitemClick(TrucksCarrier info);

        void OnInquiryClick(TrucksCarrier info);

        void CallPhone(TrucksCarrier info);

        void goHome(TrucksCarrier info);
    }


    public FreightCarTransportationAdapter(@Nullable List<TrucksCarrier> data) {
        super(R.layout.freight_car_transportation_item, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, TrucksCarrier info) {
        if (info == null) {
            return;
        }
        ViewDataBinding binding = DataBindingUtil.bind(helper.itemView);
        binding.setVariable(BR.viewModel, info);
        RoundedImageView iv_logo = helper.getView(R.id.iv_logo);
        switch (info.getTerminal()) {
            case "1":
                iv_logo.setOval(false);
                iv_logo.setCornerRadius(4);
                break;
            case "2":
                //个人不展示
            case "3":
                iv_logo.setOval(true);
                break;
        }
        String address = "";
        if (!TextUtils.isEmpty(info.getCityName())) {
            address += info.getCityName();
        }
        if (!TextUtils.isEmpty(info.getDistrictName())) {
            address += " " + info.getDistrictName();
        }
        address += " → ";
        if (!TextUtils.isEmpty(info.getDestCityName())) {
            address += info.getDestCityName() + " ";
        }
        if (!TextUtils.isEmpty(info.getDestDistrictName())) {
            address += info.getDestDistrictName();
        }
        helper.setText(R.id.car_item_city_name, address);
        boolean isSameDay = !TextUtils.isEmpty(info.getShipmentEndTime()) && DateUtils.stampToDay5(info.getShipmentEndTime()) .equals( DateUtils.stampToDay5(info.getShipmentTime()));
        helper.setText(R.id.deliver_dest_pace, info.getRoleName())
                .setText(R.id.car_item_number, TextUtils.isEmpty(info.getTelphone()) ? "/" : info.getTelphone())
                .setText(R.id.car_item_freight, (info.getDiscuss() == 1?"商议":(TextUtils.isEmpty(info.getKilometre())?"":NumberUtil.trim0(info.getKilometre())+"公里内")+NumberUtil.trim0(info.getFreight()) + info.getFreightUnit()))
                .setText(R.id.car_item_time, isSameDay?DateUtils.stampToDay5(info.getShipmentTime()):DateUtils.stampToDay5(info.getShipmentTime()) + "-" + DateUtils.stampToDay5(info.getShipmentEndTime()))
                .setText(R.id.info_status, info.getCarTypeName() + "/" + info.getCarLenName())
                .setText(R.id.car_item_number,TextUtils.isEmpty(info.getCarNumber())?"/":info.getCarNumber())
                .setText(R.id.car_item_contacts,TextUtils.isEmpty(info.getContrcts())?"/":info.getContrcts())
        .setText(R.id.car_item_phone,TextUtils.isEmpty(info.getContrctsNumber())?"/":info.getContrctsNumber());
        SeeMoreView load_goods_time = helper.getView(R.id.load_goods_time);
        load_goods_time.setText(TextUtils.isEmpty(info.getNote()) ? "/" : info.getNote().trim());
        helper.getView(R.id.content_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.OnitemClick(info);
            }
        });
        helper.getView(R.id.car_item_inquiry).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.OnInquiryClick(info);
            }
        });
        helper.getView(R.id.car_item_number).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.CallPhone(info);
            }
        });
        helper.getView(R.id.identity_info).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.goHome(info);
            }
        });
    }


    public void setListener(GoodsOperationListener listener) {
        this.listener = listener;
    }

}
